<template>
	<div class="alarmConfiguration zy-content">
		<search :columns="searchData" @getSearch="getSearch(arguments)"></search>
		<div class="list-layout mt16">
			<div class="btns clear">
				<span class="title">{{ $t('common.listInformation') }}</span>
				<Button @click="exportTemplateClick">{{ $t('common.batchExport') }}</Button>
				<Button @click="getTableColumns(columns)">
					{{ handleContextMenuStatus ? $t('显示操作栏') : $t('隐藏操作栏') }}
				</Button>
			</div>
			<div class="tableContent">
				<Table
					class="resizable-table"
					border
					@on-column-width-resize="onColumnWidthResize"
					:columns="columnsList"
					ellipsis
					ref="selection"
					stripe
					:data="dataArr"
					@on-selection-change="onSelectChange"
				>
				</Table>
			</div>
			<div class="pageWrap mt16">
				<pageLeftTitle :total="total" :selected="delIds.length" />
				<Page
					:total="total"
					:page-size="pageSize"
					:page-size-opts="pageSizeOption"
					:current="pageNum"
					@on-change="changePageNum"
					@on-page-size-change="changePageSize"
					show-sizer
					show-total
				/>
			</div>
		</div>
	</div>
</template>

<script>
import search from '@/components/curd/searchList.vue';
import fileDownload from 'js-file-download';
import toggleTableOperation from '@/mixins/toggleTableOperation';
export default {
	name: 'benchmarkActualAnalysis',
	components: { search },
	mixins: [toggleTableOperation],
	data() {
		return {
			importExcelState: false /*批量导入*/,
			allCheck: false,
			loading: false,
			searchParams: {},
			pageNum: 1,
			pageSize: 10,
			total: 0,

			searchData: [
				// {
				//     title: "功能位置",
				//     key: "mlocation",
				//     type: "cascader",
				//     dicUrl: "/basic/organization/findListByToken?level=0",
				//     params: {
				//         label: "name",
				//         value: "code",
				//         children: "children",
				//     },
				// },
				{
					title: '工单号',
					key: 'workCode',
				},
				{
					title: '模具编号',
					key: 'moldCode',
				},
				{
					title: '模具名称',
					key: 'moldName',
				},
				{
					title: '产品编号',
					key: 'materialCode',
				},
				{
					title: '产品型号',
					key: 'materialModel',
				},
				{
					title: '产品名称',
					key: 'materialName',
					// type: "select",
				},
				{
					title: '生产日期',
					key: 'scheduleDate',
					type: 'date',
					// cascader: 'shift',
				},
				{
					title: '生产班次',
					key: 'shift',
          // queryName: "planName",
					// type: "search",
					// dicUrl: "/dms/mobile/getShiftList",

					// params: {
					// 	label: "shift",
					// 	value: "shift",
					// },
				},
			],
			columns: [
				{
					key: 'selection',
					type: 'selection',
					width: 60,
					align: 'center',
				},
				{
					title: '生产日期',
					key: 'scheduleDate',
					minWidth: 130,
					align: 'center',
					resizable: true,
				},
				{
					title: '生产班次',
					key: 'shift',
					minWidth: 130,
					align: 'center',
					resizable: true,
				},
				{
					title: '工单号',
					key: 'workCode',
					minWidth: 130,
					align: 'center',
					resizable: true,
				},
				{
					title: '模具编号',
					key: 'moldCode',
					minWidth: 130,
					align: 'center',
					resizable: true,
				},
				{
					title: '模具名称',
					key: 'moldName',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '产品编号',
					key: 'materialCode',
					minWidth: 130,
					align: 'center',
					resizable: true,
				},
				{
					title: '产品型号',
					key: 'materialModel',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '产品名称',
					key: 'materialName',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				// {
				//     title: '状态',
				//     key: 'status',
				//     minWidth: 150,
				//     slot: 'model',
				//     align: 'center',
				//     resizable: true
				// },
				// {
				//     title: '满穴数',
				//     key: 'remark',
				//     minWidth: 150,
				//     align: 'center',
				//     resizable: true
				// },
				{
					title: '基准周期时间（秒）',
					key: 'standardTimeCycle',
					minWidth: 180,
					align: 'center',
					resizable: true,
				},
				{
					title: '基准工时定额',
					key: 'benchmarkWorkHourQuota',
					minWidth: 180,
					align: 'center',
					resizable: true,
				},
				{
					title: '基准班产定额',
					key: 'benchmarkClassProductionQuota',
					minWidth: 180,
					align: 'center',
					resizable: true,
				},
				{
					title: '单产品穴数',
					key: 'realityCavityNum',
					minWidth: 180,
					align: 'center',
					resizable: true,
				},
				{
					title: '实际周期时间（秒）',
					key: 'actualCycleTime',
					minWidth: 180,
					align: 'center',
					resizable: true,
				},
				{
					title: '实际工时定额',
					key: 'actualWorkingHoursQuota',
					minWidth: 180,
					align: 'center',
					resizable: true,
				},
				{
					title: '实际班产定额',
					key: 'actualClassProductionQuota',
					minWidth: 180,
					align: 'center',
					resizable: true,
				},
				{
					title: '工时偏差',
					key: 'workHourDeviation',
					minWidth: 180,
					align: 'center',
					resizable: true,
					render: (h, params) => {
						return h('div', (100 * params.row.workHourDeviation).toFixed(0) + '%');
					},
				},
				{
					title: '周期时间偏差',
					key: 'cycleTimeDeviation',
					minWidth: 180,
					align: 'center',
					resizable: true,
					render: (h, params) => {
						return h('div', (100 * params.row.cycleTimeDeviation).toFixed(0) + '%');
					},
				},

				// {
				//     //title: '操作',
				//     title: `${this.$t('common.operation')}`,
				//     slot: "action",
				//     fixed: 'right',
				//     minWidth: 160,
				//     align: "center"
				// }
			],
			dataArr: [],
			pageSizeOption: [10, 20, 30, 40],
			delIds: [],
			selection: [],
		};
	},
	mounted() {
		this.getTableColumnsWidth(this.columns);
		this.searchList();
	},
	methods: {
		getSearch(arg) {
			this.searchParams = JSON.parse(JSON.stringify(arg[0]));
			this.pageNum = 1;
			this.searchList();
		},
		reset() {
			this.searchParams = {};
			this.changeNum();
		},
		//分页
		changeNum() {
			this.pageNum = 1;
			this.searchList();
		},
		changePageSize(pageSize) {
			this.pageSize = pageSize;
			this.searchList();
		},

		changePageNum(val) {
			this.pageNum = val;
			this.searchList();
		},
		//查询列表
		searchList() {
			let params = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				...this.searchParams,
			};
			this.axios({
				method: 'post',
				url: '/dms/workBenchmarkAnalysis/workBenchmarkAnalysisPage',
				data: params,
			}).then((res) => {
				if (res.code === 200) {
					this.dataArr = res.data.list;
					this.total = res.data.total;
				} else {
					this.$Message.warning({ content: res.msg, duration: 6, closable: true });
				}
			});
		},
		//勾选列表
		onSelectChange(selection) {
			let myArray = [];
			selection.map((item, index) => {
				myArray.push(item.id);
			});
			this.delIds = myArray;
			if (selection.length > 0) {
				this.allCheck = true;
			} else {
				this.allCheck = false;
			}
		},
		//导出
		exportTemplateClick() {
			let params = {
				// delIds: this.delIds,
			};
			for (let key in this.searchParams) {
				if (this.searchParams[key]) {
					this.$set(params, key, this.searchParams[key]);
				}
			}
			const filName = '工单基准与实际工时分析';
			this.axios({
				url: '/dms/workBenchmarkAnalysis/export',
				responseType: 'blob',
				method: 'post',
				data: {
					...this.searchParams,
				},
			})(params).then((res) => {
				fileDownload(res, filName + '.xlsx');
			});
		},
	},
};
</script>

<style scoped lang="scss">
.ivu-input-number {
	width: -webkit-fill-available;
}

.row_click {
	cursor: pointer;
	color: rgb(50, 113, 240) !important;
}
</style>
